home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / lang / Process.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  5.4 KB  |  134 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Process.java    1.15 98/08/26
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang;
  16.  
  17. import java.io.*;
  18.  
  19. /**
  20.  * The <code>Runtime.exec</code> methods create a native process and
  21.  * return an instance of a subclass of <code>Process</code> that can 
  22.  * be used to control the process and obtain information about it. 
  23.  *  The class <code>Process</code> provides methods for performing 
  24.  * input from the process, performing output to the process, waiting 
  25.  * for the process to complete, checking the exit status of the process, 
  26.  * and destroying (killing) the process. 
  27.  * <p>
  28.  * The <code>Runtime.exec</code> methods may not work well for special
  29.  * processes on certain native platforms, such as native windowing
  30.  * processes, daemon processes, Win16/DOS processes on Win32, or shell
  31.  * scripts. The created subprocess does not have its own terminal or
  32.  * console. All its standard io (i.e. stdin, stdout, stderr)  operations
  33.  * will be redirected to the parent process through three streams
  34.  * (<code>Process.getOutputStream()</code>,
  35.  * <code>Process.getInputStream()</code>,
  36.  * <code>Process.getErrorStream()</code>).
  37.  * The parent process uses these streams to feed input to and get output
  38.  * from the subprocess. Because some native platforms only provide
  39.  * limited buffer size for standard input and output streams, failure
  40.  * to promptly write the input stream or read the output stream of
  41.  * the subprocess may cause the subprocess to block, and even deadlock.
  42.  * <p>
  43.  * The subprocess is not killed when there are no more references to 
  44.  * the <code>Process</code> object, but rather the subprocess 
  45.  * continues executing asynchronously. 
  46.  * <p>
  47.  * There is no requirement that a process represented by a <code>Process</code> 
  48.  * object execute asynchronously or concurrently with respect to the Java 
  49.  * process that owns the <code>Process</code> object.
  50.  *
  51.  * @author  unascribed
  52.  * @version 1.15, 08/26/98
  53.  * @see     java.lang.Runtime#exec(java.lang.String)
  54.  * @see     java.lang.Runtime#exec(java.lang.String, java.lang.String[])
  55.  * @see     java.lang.Runtime#exec(java.lang.String[])
  56.  * @see     java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
  57.  * @since   JDK1.0
  58.  */
  59. public abstract class Process
  60. {
  61.     /**
  62.      * Gets the output stream of the subprocess.
  63.      * Output to the stream is piped into the standard input stream of 
  64.      * the process represented by this <code>Process</code> object. 
  65.      * <p>
  66.      * Implementation note: It is a good idea for the output stream to 
  67.      * be buffered.
  68.      *
  69.      * @return  the output stream connected to the normal input of the
  70.      *          subprocess.
  71.      */
  72.     abstract public OutputStream getOutputStream();
  73.  
  74.     /**
  75.      * Gets the input stream of the subprocess.
  76.      * The stream obtains data piped from the standard output stream 
  77.      * of the process represented by this <code>Process</code> object. 
  78.      * <p>
  79.      * Implementation note: It is a good idea for the input stream to 
  80.      * be buffered.
  81.      *
  82.      * @return  the input stream connected to the normal output of the
  83.      *          subprocess.
  84.      */
  85.     abstract public InputStream getInputStream();
  86.  
  87.     /**
  88.      * Gets the error stream of the subprocess.
  89.      * The stream obtains data piped from the error output stream of the 
  90.      * process represented by this <code>Process</code> object. 
  91.      * <p>
  92.      * Implementation note: It is a good idea for the input stream to be 
  93.      * buffered.
  94.      *
  95.      * @return  the input stream connected to the error stream of the
  96.      *          subprocess.
  97.      */
  98.     abstract public InputStream getErrorStream();
  99.  
  100.     /**
  101.      * causes the current thread to wait, if necessary, until the 
  102.      * process represented by this <code>Process</code> object has 
  103.      * terminated. This method returns 
  104.      * immediately if the subprocess has already terminated. If the
  105.      * subprocess has not yet terminated, the calling thread will be
  106.      * blocked until the subprocess exits.
  107.      *
  108.      * @return     the exit value of the process. By convention, 
  109.      *             <code>0</code> indicates normal termination.
  110.      * @exception  InterruptedException  if the current thread is 
  111.      *             {@link Thread#interrupt() interrupted} by another thread 
  112.      *             while it is waiting, then the wait is ended and an 
  113.      *             <code>InterruptedException</code> is thrown.
  114.      */
  115.     abstract public int waitFor() throws InterruptedException;
  116.  
  117.     /**
  118.      * Returns the exit value for the subprocess.
  119.      *
  120.      * @return  the exit value of the subprocess represented by this 
  121.      *          <code>Process</code> object. by convention, the value 
  122.      *          <code>0</code> indicates normal termination.
  123.      * @exception  IllegalThreadStateException  if the subprocess represented 
  124.      *             by this <code>Process</code> object has not yet terminated.
  125.      */
  126.     abstract public int exitValue();
  127.  
  128.     /**
  129.      * Kills the subprocess. The subprocess represented by this 
  130.      * <code>Process</code> object is forcibly terminated.
  131.      */
  132.     abstract public void destroy();
  133. }
  134.